//
//  JgAdsInterstitialAdContainer.m
//  AnyThinkSDKDemo
//
//  Created by 刘娟 on 2022/11/17.
//  Copyright © 2022 抽筋的灯. All rights reserved.
//

#import "JgAdsInterstitialAdContainer.h"

@interface JgAdsInterstitialAdContainer()<JgAdsInterstitialAdDelegate>

@property(nonatomic, strong) JgAdsInterstitialAd *interstitialAd;

@end

@implementation JgAdsInterstitialAdContainer
-(void)setDelegate:(id<JgAdsInterstitialAdDelegate>)delegate{
    self.interstitialAd.delegate = delegate;
}
// MARK: - Init
-(instancetype)initPosId:(NSString *)posId delegate:(id<JgAdsInterstitialAdDelegate>)delegate{
    self = [super init];
    if(self){
        self.interstitialAd = [JgAdsInterstitialAd new];
        self.interstitialAd.posId = posId;
        self.interstitialAd.delegate = delegate;
        if (delegate == nil) {
            self.interstitialAd.delegate = self;
        }
    }
    return self;
}
- (void)loadInterstitialAd{
    if(self.interstitialAd){
        [self.interstitialAd loadAdData];
    }
}
- (void)showInterstitialAdWithRootViewController:(UIViewController *)controller{
    [_interstitialAd showFromRootViewController:controller];
}
- (void)sendWinNotificationWithPrice:(NSInteger)price{
    [_interstitialAd sendWinNotificationWithPrice:price];
}
- (void)sendWinFailNotificationReason:(JgAdsBiddingLossReason)lossReason winnerPirce:(NSInteger)winnerPirce{
    [_interstitialAd sendWinFailNotificationReason:lossReason winnerPirce:winnerPirce];
}
- (void)close{
    _interstitialAd = nil;
}
- (NSInteger)getBidPrice{
    if (_interstitialAd == nil) {
        return 0;
    }
    return _interstitialAd.bidPrice;
}
#pragma mark -- JgAdsInterstitialAdDelegate
/**
 *  开屏广告素材加载成功
 */
- (void)jgadsInterstitialSuccessToLoadAd:(JgAdsInterstitialAd *)unifiedInterstitial{
#if DEBUG
        NSLog(@"jgads============插屏广告-加载成功");
#endif
    if ([self.containerDelegate respondsToSelector:@selector(jgadsContainer_jgadsInterstitialAdDidLoad:withPrice:)]) {
        [self.containerDelegate jgadsContainer_jgadsInterstitialAdDidLoad:self withPrice:unifiedInterstitial.bidPrice];
    }
}

/**
 *  开屏广告请求失败
 */
- (void)jgadsInterstitialFailToLoadAd:(JgAdsInterstitialAd *)unifiedInterstitial error:(NSError *)error{
#if DEBUG
        NSLog(@"jgads============插屏广告-加载失败：%@",error);
#endif
    if ([self.containerDelegate respondsToSelector:@selector(jgadsContainer_jgadsInterstitialAdFailLoadError:)]) {
        [self.containerDelegate jgadsContainer_jgadsInterstitialAdFailLoadError:error];
    }
}
@end
